package com.note.servlet.note;

import com.alibaba.fastjson.JSON;
import com.note.pojo.notePageShow;
import com.note.service.note.noteService;
import com.note.service.note.noteServiceImpl;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class fuzzy_queryBytitle extends HttpServlet {
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String title = req.getParameter("title");
        String str = "%";
        str = str+title+"%";
        noteService n = new noteServiceImpl();
        List<notePageShow> noteByTitle = n.getNoteByTitle(str);
        String noteJson = JSON.toJSONString(noteByTitle, true);
        PrintWriter out = resp.getWriter();
        out.write(noteJson);
        out.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
